﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DacSanMienTayOBJ;
using System.Text;
public partial class Proccess_ProccessLockAndUnlockAdvertising : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LockUnlockAdv();
    }

    private void LockUnlockAdv()
    {
        try
        {
            int advID = int.Parse(Request["advID"]);
            string type = Request["type"];
            int vt = int.Parse(Request["vt"]);
            string advPositionName = Request["advPoName"];
            StringBuilder builder = new StringBuilder();
            if (type == "lock")
            {
                bool rs = AdvertisingBusiness.LockAndUnlockAdvertising(advID, 0, ConnectionType.AdminConnection);
                if (rs)
                {
                    Advertising adv = AdvertisingBusiness.GetAdvertisingDetail(advID, ConnectionType.AdminConnection);
                    string advName = adv.AdvName;
                   
                    string logo = Utility.modHost + "/" + adv.Logo;
                    string status = "";
                    if (adv.IsVisible == 1)
                    {
                        status = "Active";
                    }
                    else
                    {
                        status = "Inactive";
                    }
                    string link = adv.Link;


                    builder.Append("<td>"+advName+" </td>");
                    builder.Append("<td><img src=\""+logo+"\" width=\"100px\" height=\"100px\" /></td>");
                    builder.Append("<td>"+link+"</td>");
                    builder.Append("<td>"+advPositionName+"</td>");
                    builder.Append("<td>"+status+"</td>");

                    builder.Append("<td>");
 
               builder.Append("<span style=\"color:Blue; cursor:pointer\" title=\""+advName+"\" id=\""+link+"\"  onclick=\"ShowInfoAdvertising('"+adv.AdvertisingID+"','"+adv.AdvPositionID+"','"+logo+"',this.title,this.id,'"+adv.Note+"')\"> Chỉnh sữa</span>");
               builder.Append("</td>");
               builder.Append("<td>");

                    if (adv.IsVisible == 1)
                    {

                        builder.Append("<input type=\"button\" title=\"" + adv.AdvertisingID + "\"  value=\"Khóa\" onclick=\"LockAndUnlockAdvertising(this.title,'lock','" + vt + "','" + advPositionName + "')\" />");

                    }
                    else
                    {

                        builder.Append("<input type=\"button\" title=\"" + adv.AdvertisingID + "\"  value=\"Mở khóa\" onclick=\"LockAndUnlockAdvertising(this.title,'unlock','" + vt + "','" + advPositionName + "')\" />");
                    }
         
                 builder.Append("</td>");

                 Response.Write(builder);
                }
                else
                {
                    Response.Write("lockfaile");
                }
            }
            else if (type == "unlock")
            {
                bool rs = AdvertisingBusiness.LockAndUnlockAdvertising(advID, 1, ConnectionType.AdminConnection);
                if (rs)
                {
                    Advertising adv = AdvertisingBusiness.GetAdvertisingDetail(advID, ConnectionType.AdminConnection);
                    string advName = adv.AdvName;
                  
                    string logo = Utility.modHost + "/" + adv.Logo;
                    string status = "";
                    if (adv.IsVisible == 1)
                    {
                        status = "Active";
                    }
                    else
                    {
                        status = "Inactive";
                    }
                    string link = adv.Link;


                    builder.Append("<td>" + advName + " </td>");
                    builder.Append("<td><img src=\"" + logo + "\" width=\"100px\" height=\"100px\" /></td>");
                    builder.Append("<td>" + link + "</td>");
                    builder.Append("<td>" + advPositionName + "</td>");
                    builder.Append("<td>" + status + "</td>");

                    builder.Append("<td>");

                    builder.Append("<span style=\"color:Blue; cursor:pointer\" title=\"" + advName + "\" id=\"" + link + "\"  onclick=\"ShowInfoAdvertising('" + adv.AdvertisingID + "','" + adv.AdvPositionID + "','" + logo + "',this.title,this.id,'" + adv.Note + "')\"> Chỉnh sữa</span>");
                    builder.Append("</td>");
                    builder.Append("<td>");

                    if (adv.IsVisible == 1)
                    {

                        builder.Append("<input type=\"button\" title=\"" + adv.AdvertisingID + "\"  value=\"Khóa\" onclick=\"LockAndUnlockAdvertising(this.title,'lock','" + vt + "','" + advPositionName + "')\" />");

                    }
                    else
                    {

                        builder.Append("<input type=\"button\" title=\"" + adv.AdvertisingID + "\"  value=\"Mở khóa\" onclick=\"LockAndUnlockAdvertising(this.title,'unlock','" + vt + "','" + advPositionName + "')\" />");
                    }

                    builder.Append("</td>");
                    Response.Write(builder);
                }
                else
                {
                    Response.Write("unlockfaile");
                }
            }
            Response.End();
        }
        catch
        {

        }
    }
}